//
//  ZTDetailHeaderView.m
//  FD
//
//  Created by xiaofang wang on 2019/1/22.
//  Copyright © 2019年 ZhiYuan Network. All rights reserved.
//  上:10px+60 +10

#import "ZTDetailHeaderView.h"
//10px间距 实现灰色线效果
#define kLineMargin 10
//左右间距
#define kLeftRightMargin 15

@interface ZTDetailHeaderView()
/**上 图标 + 店名字 + 详细地址 */
@property (nonatomic, strong) UIView *upBgView;
/**icon*/
@property (nonatomic, strong) UIImageView *iconIv;
/**店名*/
@property (nonatomic, strong) UILabel *shopNameLb;
/**详细地址*/
@property (nonatomic, strong) UILabel *addressLb;
@end



@implementation ZTDetailHeaderView

#pragma mark - 一 init
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
        self.backgroundColor = kMainLightGrayColor; //浅灰色。子控件留出就距离实现分割线效果。
    }
    return self;
}

- (void)setupUI {
    
    //上 距上10px 作为间距
    [self addSubview:self.upBgView];
    [self.upBgView addSubview:self.iconIv];
    [self.upBgView addSubview:self.shopNameLb];
    [self.upBgView addSubview:self.addressLb];
}

#pragma mark - 二 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self layoutUpBgViews];
}

- (void)layoutUpBgViews {
    [self.upBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.top.equalTo(self.mas_top).offset(kLineMargin);
        make.right.equalTo(self.mas_right);
        make.height.mas_equalTo(60);
    }];
    
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.upBgView.mas_left).offset(kLeftRightMargin);
        make.size.mas_equalTo(CGSizeMake(15, 20));
        make.centerY.equalTo(self.upBgView.mas_centerY);
    }];
    
    [self.shopNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(5);
        make.top.equalTo(self.upBgView.mas_top);
        make.height.mas_equalTo(20);
        make.right.equalTo(self.upBgView.mas_right).offset(-kLeftRightMargin);
    }];
    
    [self.addressLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.shopNameLb.mas_left);
        make.top.equalTo(self.shopNameLb.mas_bottom); //.offset(5);
        make.right.equalTo(self.mas_right).offset(-kLeftRightMargin);
        make.bottom.equalTo(self.upBgView.mas_bottom);
    }];
}

#pragma mark - 三 接口
- (void)ztDetailHeaderViewUpdateShopName:(NSString *)name address:(NSString *)address {
    self.shopNameLb.text = name;
    self.addressLb.text = address;
}

#pragma mark - 四 getter
- (UIView *)upBgView {
    if (!_upBgView) {
        _upBgView = [[UIView alloc] init];
        _upBgView.backgroundColor = [UIColor whiteColor]; //白色背景
    }
    return _upBgView;
}
- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"address"]];
    }
    return _iconIv;
}
- (UILabel *)shopNameLb {
    if (!_shopNameLb) {
        _shopNameLb = [[UILabel alloc] init];
        _shopNameLb.text = @"Marina Branch";
        _shopNameLb.font = [UIFont systemFontOfSize:15.0];
        _shopNameLb.textColor = kLightGrayTextColor;
    }
    return _shopNameLb;
}
- (UILabel *)addressLb {
    if (!_addressLb) {
        _addressLb = [[UILabel alloc] init];
        _addressLb.font = [UIFont systemFontOfSize:15.0];
        _addressLb.textColor = kLightGrayTextColor;
        _addressLb.text = @"Center Park Rd , Ballinetemple ,Cork, Ireland";
        _addressLb.numberOfLines = 0; //允许换行
    }
    return _addressLb;
}
@end
